home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / execd1200.iso / Shareware / Blocks 3 / setup.exe / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-07  |  10.2 KB  |  487 lines

  1. #include <allegro.h>
  2. #include <jgmod.h>
  3. #include <libcda.h>
  4. #include <blocks3.h>
  5.  
  6. int i, j, full_exit;
  7.  
  8. int main(void)
  9. {
  10.  Initialise();
  11.  
  12. /* play_mod (music, TRUE);*/
  13.  
  14.  Presents();
  15.  
  16.  Title();
  17.  Log_In();
  18.  
  19.  full_exit = 1;
  20.  
  21.  while (full_exit)
  22.  {
  23.   full_exit = Title_Menu();
  24.  
  25.   if (full_exit == 1)
  26.   {
  27.    Transition_Out(title_gfx, title_pallete);
  28. /*   fade_out(10);*/
  29.    Editor();
  30.    Title();
  31.   }
  32.  
  33.   if ((full_exit == 2) && (Open_Maps_Title() == 1))
  34.   {
  35.    Transition_Out(title_gfx, title_pallete);
  36.    Full_Game();
  37.    Title();
  38.   }
  39.  }
  40.  Transition_Out(title_gfx, title_pallete);
  41.  
  42.  cd_stop();
  43.  cd_exit();
  44.  
  45.  allegro_exit();
  46. }
  47.  
  48. void Init_Level(void)
  49. {
  50.  int i, j, k;
  51.  
  52.  no_ply = 1;
  53.  
  54.  for (i = 0; i < 20; i++)
  55.  for (j = 0; j < 15; j++)
  56.  for (k = 0; k < 2; k++)
  57.  {
  58.   if (map[i][j][k] == AUDREY)
  59.   {
  60.    map[i][j][k] = 0;
  61.    ply[0].x = i*32;
  62.    ply[0].y = j*32;
  63.    ply[0].z = k*8;
  64.    ply[0].dx = 0;
  65.    ply[0].dy = 0;
  66.    ply[0].dz = 0;
  67.   }
  68.   if (map[i][j][k] == AN)
  69.   {
  70.    map[i][j][k] = 0;
  71.    ply[1].x = i*32;
  72.    ply[1].y = j*32;
  73.    ply[1].z = k*8;
  74.    ply[1].dx = 0;
  75.    ply[1].dy = 0;
  76.    ply[1].dz = 0;
  77.    no_ply = 2;
  78.   }
  79.  
  80.   map_laser[i][j][k] = 0;
  81.  }
  82. }
  83.  
  84.  
  85. int Run_Level(void)
  86. {
  87.  Change_Motif(map_motif[lev]);
  88.  
  89.  Draw_Map();
  90.  Init_Level();
  91.  Map_Setup();
  92.  
  93. /* set_pallete(black_pallete);
  94.  blit(temp, screen, 0, 0, 0, 0, 640, 480);
  95.  fade_in(pallete, 10);*/
  96.  
  97.  set_pallete(pallete);
  98.  
  99.  Transition_In(temp, pallete);
  100.  
  101.  Get_Ready();
  102.  
  103.  game_exit = 0;
  104.  
  105.  while (!game_exit)
  106.  {
  107.   Box_Move();
  108.   Box_Fall();
  109.  
  110.   Bomb_Prime_Laser();
  111.  
  112.   Player_Fall(0);
  113.   Player_Fall(1);
  114.  
  115.   if ((key[KEY_CONTROL]) && (no_ply == 2)) Player_Input(1);
  116.   else Player_Input(0);
  117.  
  118.   if (no_ply == 2) Player2_Input(1);
  119.  
  120.   Player_Move(0);
  121.   if (no_ply == 2) Player_Move(1);
  122.   Player_Pickup_Check(0);
  123.   if (no_ply == 2) Player_Pickup_Check(1);
  124.   Player_Draw(0);
  125.   if (no_ply == 2) Player_Draw(1);
  126.  
  127.   Check_Fall(0);
  128.   if (no_ply == 2) Check_Fall(1);
  129.  
  130.   Check_Fall_Prime();
  131.  
  132.   Monster();
  133.  
  134.   Laser();
  135.   Door();
  136.  
  137.   Player_Monster_Collision(0);
  138.   Player_Laser_Collision(0);
  139.   if (no_ply == 2) Player_Monster_Collision(1);
  140.   if (no_ply == 2) Player_Laser_Collision(1);
  141.  
  142.   Draw_Explode();
  143.  
  144.   Draw_Screen();
  145.   Play_Sound();
  146.  
  147.  
  148. /*  textprintf(screen, font, 10, 10, 7, "%d ", undo_count);
  149.  
  150. /* text_mode(0);
  151.  
  152.   for (i = 0; i< 20; i++)
  153.   for (j = 0; j< 15; j++)
  154.   textprintf(screen, font, i*32, j*32, 7, "%d ", (map[i][j][0]));*/
  155.  
  156.   if (Token_Count()) game_exit = 3;
  157.  
  158.   while(time_count < 1);
  159.   time_count = 0;
  160.  
  161.   if ((key[KEY_ESC]) && (game_type == EDITOR_GAME)) game_exit = 2;
  162.   if ((key[KEY_ESC]) && (game_type == PLAYER_GAME)) In_Game_Menu();
  163.  
  164.   if (key[KEY_F2])
  165.   {
  166.    while(key[KEY_F2]);
  167.    Maps_to_Map(lev);
  168.    Draw_Map();
  169.    Init_Level();
  170.    Map_Setup();
  171.    blit(temp, screen, 0, 0, 0, 0, 640, 480);
  172.   }
  173.  
  174.   if (key[KEY_BACKSPACE])
  175.   {
  176.    while(key[KEY_BACKSPACE]);
  177.    Undo();
  178.   }
  179.  }
  180.  
  181.  
  182.  if (game_exit == 1)
  183.  {
  184.   Player_Death(0);
  185.   blit(screen, temp, 0, 0, 0, 0, 640, 480);
  186.   Transition_Out(temp, pallete);
  187.   return -1;
  188.  }
  189.  if (game_exit == 3)
  190.  {
  191.   Well_Done();
  192.   blit(screen, temp, 0, 0, 0, 0, 640, 480);
  193.   Transition_Out(temp, pallete);
  194.   return 1;
  195.  }
  196.  
  197.  return 0;
  198. }
  199.  
  200. void Full_Game(void)
  201. {
  202.  int exit_full_game;
  203.  
  204.  lev = 0;
  205.  exit_full_game = 1;
  206.  game_type = PLAYER_GAME;
  207.  
  208.  Init_Full_Game();
  209.  
  210.  while (exit_full_game)
  211.  {
  212.   Maps_to_Map(lev);
  213.   exit_full_game = Run_Level();
  214.  
  215.   if (exit_full_game == 1)
  216.   {
  217.    map_done[lev] = 1;
  218.    lev = Next_Level();
  219.  
  220.    if (lev == 999)
  221.    {
  222.     for (lev = 0; lev < 100; lev++)
  223.     map_done[lev] = 0;
  224.  
  225.     exit_full_game = 0;
  226.    }
  227.   }
  228.  }
  229.  
  230.  Save_Map_Done();
  231. }
  232.  
  233. int Token_Count(void)
  234. {
  235.  int i, j, k;
  236.  
  237.  for (k = 0; k < 2; k++)
  238.  for (j = 0; j < 15; j++)
  239.  for (i = 0; i < 20; i++)
  240.  if (map[i][j][k] == TOKEN) return 0;
  241.  
  242.  return 1;
  243. }
  244.  
  245. void Get_Ready(void)
  246. {
  247.  BITMAP *temp2 = create_bitmap(640, 480);
  248.  
  249.  blit(temp, temp2, 0, 0, 0, 0, 640, 480);
  250.  
  251.  text_mode(-1);
  252.  
  253.  textprintf_centre(temp2, fonts[1].dat, 320, 149, 0, "GET.READY!");
  254.  textprintf_centre(temp2, fonts[1].dat, 321, 149, 0, "GET.READY!");
  255.  textprintf_centre(temp2, fonts[1].dat, 321, 150, 0, "GET.READY!");
  256.  textprintf_centre(temp2, fonts[1].dat, 321, 151, 0, "GET.READY!");
  257.  textprintf_centre(temp2, fonts[1].dat, 320, 151, 0, "GET.READY!");
  258.  textprintf_centre(temp2, fonts[1].dat, 319, 151, 0, "GET.READY!");
  259.  textprintf_centre(temp2, fonts[1].dat, 319, 150, 0, "GET.READY!");
  260.  textprintf_centre(temp2, fonts[1].dat, 319, 149, 0, "GET.READY!");
  261.  
  262.  textprintf_centre(temp2, fonts[1].dat, 320, 150, 7, "GET.READY!");
  263.  
  264.  blit(temp2, screen, 0, 0, 0, 0, 640, 480);
  265.  
  266.  play_sample(sfx[SFX_GETRED].dat, 255, 128, 1000, 0);
  267.  
  268.  while(key[KEY_ENTER]);
  269.  while(!key[KEY_ENTER]);
  270.  blit(temp, screen, 0, 0, 0, 0, 640, 480);
  271.  while(key[KEY_ENTER]);
  272. }
  273.  
  274. void Well_Done(void)
  275. {
  276.  BITMAP *temp2 = create_bitmap(640, 480);
  277.  
  278.  blit(screen, temp2, 0, 0, 0, 0, 640, 480);
  279.  
  280.  text_mode(-1);
  281.  
  282.  textprintf_centre(temp2, fonts[1].dat, 320, 149, 0, "WELL.DONE!");
  283.  textprintf_centre(temp2, fonts[1].dat, 321, 149, 0, "WELL.DONE!");
  284.  textprintf_centre(temp2, fonts[1].dat, 321, 150, 0, "WELL.DONE!");
  285.  textprintf_centre(temp2, fonts[1].dat, 321, 151, 0, "WELL.DONE!");
  286.  textprintf_centre(temp2, fonts[1].dat, 320, 151, 0, "WELL.DONE!");
  287.  textprintf_centre(temp2, fonts[1].dat, 319, 151, 0, "WELL.DONE!");
  288.  textprintf_centre(temp2, fonts[1].dat, 319, 150, 0, "WELL.DONE!");
  289.  textprintf_centre(temp2, fonts[1].dat, 319, 149, 0, "WELL.DONE!");
  290.  
  291.  textprintf_centre(temp2, fonts[1].dat, 320, 150, 7, "WELL.DONE!");
  292.  
  293.  blit(temp2, screen, 0, 0, 0, 0, 640, 480);
  294.  
  295.  play_sample(sfx[SFX_WELLDONE].dat, 255, 128, 1000, 0);
  296.  
  297.  while(key[KEY_ENTER]);
  298.  while(!key[KEY_ENTER]);
  299.  while(key[KEY_ENTER]);
  300. }
  301.  
  302. void Init_Full_Game(void)
  303. {
  304.  int i;
  305.  char fn[100];
  306.  PACKFILE *file;
  307.  
  308.  clear(screen);
  309.  set_pallete(pallete);
  310.  
  311.  for (i = 0; i < 100; i++)
  312.  map_done[i] = 0;
  313.  
  314.  strcpy(fn, "./");
  315.  strcat(fn, login);
  316.  strcat(fn, "/");
  317.  strcat(fn, map_save);
  318.  
  319.  if (!exists(fn)) return;
  320.  
  321.  file = pack_fopen(fn, "rp");
  322.  
  323.  for (i = 0; i < 100; i++)
  324.  map_done[i] = pack_igetw(file);
  325.  
  326.  pack_fclose(file);
  327.  
  328.  lev = 0;
  329.  lev = Next_Level();
  330. }
  331.  
  332.  
  333. void Save_Map_Done(void)
  334. {
  335.  int i;
  336.  char fn[100];
  337.  PACKFILE *file;
  338.  
  339.  strcpy(fn, "./");
  340.  strcat(fn, login);
  341.  strcat(fn, "/");
  342.  strcat(fn, map_save);
  343.  
  344.  file = pack_fopen(fn, "wp");
  345.  
  346.  for (i = 0; i < 100; i++)
  347.  pack_iputw(map_done[i], file);
  348.  
  349.  pack_fclose(file);
  350. }
  351.  
  352. int Next_Level(void)
  353. {
  354.  int l, i, j, k, tk;
  355.  
  356.  for (l = lev; l < 100; l++)
  357.  {
  358.   if (map_done[l] == 0)
  359.   {
  360.    tk = 0;
  361.  
  362.    for (i = 0; i < 20; i++)
  363.    for (j = 0; j < 15; j++)
  364.    for (k = 0; k < 2; k++)
  365.    if (maps[i][j][k][l] == TOKEN) tk++;
  366.  
  367.    if (tk != 0) return l;
  368.   }
  369.  }
  370.  
  371.  for (l = 0; l < 100; l++)
  372.  {
  373.   if (map_done[l] == 0)
  374.   {
  375.    tk = 0;
  376.  
  377.    for (i = 0; i < 20; i++)
  378.    for (j = 0; j < 15; j++)
  379.    for (k = 0; k < 2; k++)
  380.    if (maps[i][j][k][l] == TOKEN) tk++;
  381.  
  382.    if (tk != 0) return l;
  383.   }
  384.  }
  385.  
  386.  Finish_Game();
  387.  return 999;
  388. }
  389.  
  390. void Finish_Game(void)
  391. {
  392.  clear(screen);
  393.  
  394.  set_pallete(black_pallete);
  395.  
  396.  textprintf_centre(screen, fonts[0].dat, 320, 20, 7, "CONGRAGULATIONS!");
  397.  textprintf_centre(screen, fonts[0].dat, 320, 100, 7, "You have completed the");
  398.  textprintf_centre(screen, fonts[0].dat, 320, 160, makecol(255, 255, 0), "%s", map_save);
  399.  textprintf_centre(screen, fonts[0].dat, 320, 220, 7, "levelset of Blocks3:Ultra");
  400.  textprintf_centre(screen, fonts[0].dat, 320, 280, 7, "Thankyou for playing!");
  401.  
  402.  fade_in(pallete, 10);
  403.  
  404.  while(key[KEY_ENTER]);
  405.  while(!key[KEY_ENTER]);
  406. }
  407.  
  408. void Convert(void)
  409. {
  410.  int i, j, k, l;
  411.  PACKFILE *file;
  412.  
  413.  file = pack_fopen("./maps/blocks2.map", "rp");
  414.  
  415.  for (k = 0; k < 100; k++)
  416.  for (j = 0; j < 15; j++)
  417.  for (i = 0; i < 20; i++)
  418.  maps[i][j][1][k] = pack_getc(file);
  419.  
  420.  pack_fclose(file);
  421.  
  422.  for (k = 0; k < 100; k++)
  423.  for (i = 0; i < 20; i++)
  424.  for (j = 0; j < 15; j++)
  425.  {
  426.   if (maps[i][j][1][k] == OLD_SOLID) maps[i][j][0][k] = SOLID;
  427.   if (maps[i][j][1][k] == OLD_BOX)   maps[i][j][0][k] = BOX;
  428.   if (maps[i][j][1][k] == OLD_TOKEN) maps[i][j][0][k] = TOKEN;
  429.   if (maps[i][j][1][k] == OLD_FALL)  maps[i][j][0][k] = FALL;
  430.   if (maps[i][j][1][k] == OLD_AUDREY) maps[i][j][0][k] = AUDREY;
  431.   if (maps[i][j][1][k] == OLD_AN)     maps[i][j][0][k] = AN;
  432.   if (maps[i][j][1][k] == OLD_LASER_UP)    maps[i][j][0][k] = LASER_UP;
  433.   if (maps[i][j][1][k] == OLD_LASER_DOWN)  maps[i][j][0][k] = LASER_DOWN;
  434.   if (maps[i][j][1][k] == OLD_LASER_LEFT)  maps[i][j][0][k] = LASER_LEFT;
  435.   if (maps[i][j][1][k] == OLD_LASER_RIGHT) maps[i][j][0][k] = LASER_RIGHT;
  436.   if (maps[i][j][1][k] == OLD_LASER_4WAY)  maps[i][j][0][k] = LASER_4WAY;
  437.   if (maps[i][j][1][k] == OLD_MIRROR_PLUS) maps[i][j][0][k] = MIRROR_PLUS;
  438.   if (maps[i][j][1][k] == OLD_MIRROR_MINUS) maps[i][j][0][k] = MIRROR_MINUS;
  439.   if (maps[i][j][1][k] == OLD_BOMB)         maps[i][j][0][k] = BOMB1;
  440.   if (maps[i][j][1][k] == OLD_BOMB2)        maps[i][j][0][k] = BOMB2;
  441.   if (maps[i][j][1][k] == OLD_DOOR1)        maps[i][j][0][k] = RED_DOOR_CLOSE;
  442.   if (maps[i][j][1][k] == OLD_DOOR2)        maps[i][j][0][k] = GREEN_DOOR_CLOSE;
  443.   if (maps[i][j][1][k] == OLD_DOOR3)        maps[i][j][0][k] = BLUE_DOOR_CLOSE;
  444.   if (maps[i][j][1][k] == OLD_SWITCH1)      maps[i][j][0][k] = RED_SWITCH;
  445.   if (maps[i][j][1][k] == OLD_SWITCH2)      maps[i][j][0][k] = GREEN_SWITCH;
  446.   if (maps[i][j][1][k] == OLD_SWITCH3)      maps[i][j][0][k] = BLUE_SWITCH;
  447.   if (maps[i][j][1][k] == OLD_MON1)         maps[i][j][0][k] = MON0;
  448.   if (maps[i][j][1][k] == OLD_MON2)         maps[i][j][0][k] = MON2;
  449.  }
  450.  
  451.  for (k = 0; k < 100; k++)
  452.  for (i = 1; i < 19; i++)
  453.  for (j = 1; j < 14; j++)
  454.  maps[i][j][1][k] = 0;
  455.  
  456.  for (j = 0; j < 100; j++)
  457.  {
  458.  for (i = 0; i < 20; i++)
  459.  {
  460.   maps[i][0][0][j] = SOLID;
  461.   maps[i][14][0][j] = SOLID;
  462.   maps[i][0][1][j] = RESERVE;
  463.   maps[i][14][1][j] = RESERVE;
  464.  }
  465.  
  466.  for (i = 0; i < 15; i++)
  467.  {
  468.   maps[0][i][0][j] = SOLID;
  469.   maps[19][i][0][j] = SOLID;
  470.   maps[0][i][1][j] = RESERVE;
  471.   maps[19][i][1][j] = RESERVE;
  472.  }
  473.  }
  474.  
  475.  file = pack_fopen("./maps/b2.map", "wp");
  476.  
  477.  for (l = 0; l < 100; l++)
  478.  for (k = 0; k < 2; k++)
  479.  for (j = 0; j < 15; j++)
  480.  for (i = 0; i < 20; i++)
  481.  pack_iputw(maps[i][j][k][l], file);
  482.  
  483.  pack_fclose(file);
  484. }
  485.  
  486.  
  487.